<% block_alignment = media_section.alignment.to_s[/^block_(.+)/,1] %>

<% if media_section.andand.media.present? %>
  <%= "<div class=\"block\">".html_safe if block_alignment %>
  <div class="media <%= block_alignment || media_section.alignment  %>" style="width: <%= media_section.width %>px;" >
    <% image = capture do %>
    <% 
      if media_section.width.present? && media_section.height.present?
        prefix = "#{media_section.width}x#{media_section.height}"
      end
      
      if media_section.media.file?
        src = media_section.media.url(prefix, :mode => renderer.mode)
      else
        src = media_section.media.url(:mode => renderer.mode)
      end
      %>
      <img src="<%= src %>" alt="<%= media_section.caption %>" />
    <% end %>
    <%= media_section.link.present? ? link_to(image, media_section.link.url(:mode => renderer.mode)) : image %>
    <% if media_section.caption.present? %>
      <p class="caption"><%= media_section.caption %></p>
    <% end %>
  </div>
  <%= "</div>".html_safe if block_alignment %>
<% end %>